package app.framework.freemarker.model;

import freemarker.template.TemplateMethodModel;
import jasmine.framework.common.util.StringUtil;

import java.util.Collections;
import java.util.Map;

/**
 * @author mh.z
 */
public abstract class AbstractResourceMethodModel implements TemplateMethodModel {
    private Map<String, String> mappingUrls;

    public AbstractResourceMethodModel() {
        this.mappingUrls = Collections.emptyMap();
    }

    public AbstractResourceMethodModel(Map<String, String> mappingUrls) {
        this.mappingUrls = mappingUrls;
    }

    /**
     * 返回映射的 URL
     *
     * @param originalUrl
     * @return
     */
    public String getMappedUrl(String originalUrl) {
        originalUrl = StringUtil.trim(originalUrl);

        String mappedUrl = mappingUrls.get(originalUrl);
        if (mappedUrl == null) {
            return originalUrl;
        }

        return mappedUrl;
    }

}
